﻿<template>
  <el-dialog
    v-drag-dialog
    :title="dlgTitle"
    :visible.sync="dialogFormVisible"
    ref="dlg"
    width="800px"
    :close-on-click-modal="false"
  >
    <el-form
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-position="right"
      label-width="130px"
      size="small"
      style="width: 80%; margin-left:6px;"
    >
      <el-form-item label="预约序号：" prop="XhReservationDataID" v-if="temp.XhReservationDataID>0">
        <el-input placeholder="预约序号" v-model="temp.XhReservationDataID" :disabled="temp.XhReservationDataID>0"></el-input>
      </el-form-item>
      
      <el-form-item label="预约名：" prop="XhVipName">
        <el-input placeholder="预约名" v-model="temp.XhVipName" ></el-input>
      </el-form-item>
      
      <!-- <el-form-item label="预约持续时长" prop="XhReservedDuration">
        <el-input placeholder="预约持续时长" precision = 1 v-model="temp.XhReservedDuration" ></el-input>
      </el-form-item> -->
      <el-form-item label="预约持续时长：" prop="XhReservedDuration">
        <el-input-number placeholder="预约持续时长" :precision="0" v-model="temp.XhReservedDuration" ></el-input-number>
      </el-form-item>
    
      
      <el-form-item label="预约地点" prop="XhReservedField">
        <el-radio-group v-model="temp.XhReservedField">
          <el-radio 
            v-for="item in XhReservedField"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-radio>
        </el-radio-group>
      </el-form-item>
      
      <el-form-item label="预约时间：" prop="XhReservedTime">
            <el-date-picker
          v-model="temp.XhReservedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="Cancel">取消</el-button>
      <el-button type="primary" @click="Save">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>

import { saveXhReservationInfo, getXhReservationInfo } from '@/api/xhreservation';
export default {
  components: {
    
  },
  data() {
    let checkMobile = (rule, value, callback) => {
      if (!/^1[3-9]\d{9}$/.test(value)) {
        callback(new Error('请输入正确的手机号'));
      } else callback();
    };
    return {
      dlgTitle: '',
      dialogFormVisible: false,
      temp: {
        XhReservationDataID: 0,
      },
      rules: {
        XhVipName: [
          { required: true, message: '必填字段1', trigger: 'blur' }
        ],
        XhReservedDuration: [
          { required: true, message: '必填字段2', trigger: 'blur' }
        ],
        XhReservedField: [
          { required: true, message: '必填字段3', trigger: 'blur' }
        ],
        XhReservedTime: [
          { required: true, message: '必填字段4', trigger: 'blur' }
        ]
       
      },
      
       

      
        XhReservedField: [
        {
          value: "足球场一区",
          label: "足球场一区"
        },
        {
          value: "足球场二区",
          label: "足球场二区"
        },
        {
          value: "足球场三区",
          label: "足球场三区"
        }
      ],
  
      
    };
  },
  methods: {
    AddDialog(data) {
      let row = data || null;
      this.initInfo();
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate();
      });
      this.dlgTitle = '添加预约';
    },
    EditDialog(id) {
      this.initInfo();
      this.dialogFormVisible = true;
      this.temp.XhReservationDataID = id;
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate();
      });
      this.dlgTitle = '修改课程';
      this.getRecordInfo(this.temp.XhReservationDataID);
    },
    initInfo() {
      this.temp.XhReservationDataID = 0;
      this.temp = {};
    },
    getRecordInfo(id) {
      getXhReservationInfo(id).then(rsp => {
        if (rsp.code === 0) {
          let record = rsp.data;
          this.temp = record;
        } else {
          this.dialogFormVisible = false;
          this.$message.error(rsp.msg);
        }
      });
    },
    Save() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.$confirm('确认保存？', '提示', {
            type: 'warning',
            callback: action => {
              if (action == 'confirm') {
                saveXhReservationInfo(this.temp).then(rsp => {
                  if (rsp.code === 0) {
                    this.dialogFormVisible = false;
                    this.$message.success(this.$refs.dlg.title + '成功!');
                    this.$emit('onRefresh');
                  } else {
                    this.$message.error(rsp.msg);
                  }
                });
              }
            }
          });
        }
      });
    },
    Cancel() {
      this.dialogFormVisible = false;
    }
  }
};
</script>
